import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { ServeStaticModule } from '@nestjs/serve-static';
import { AppService } from './app.service';
import { SysModule } from './sys/sys.module';
import { UploadModule } from './upload/upload.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { LoginModule } from './login/login.module';
import { AuthModule } from './auth/auth.module';
import { CustomTypeOrmLogger } from './common/log/typeormLogger';
import { join } from 'path';

import { BasedataModule } from './basedata/basedata.module';
import { SharedModule } from './shared/shared.module';
import { AppController } from './app.controller';

import { ContainerModule } from './container/container.module';
import { BusinessModule } from './business/business.module';
import { CfsModule } from './cfs/cfs.module';
import { TransportModule } from './transport/transport.module';



@Module({
    imports: [
        // 配置静态路径，指向vue3部署路径
        ServeStaticModule.forRoot({
            rootPath: join(__dirname, '..', 'client'),
            serveRoot: '/'
        }),
        TypeOrmModule.forRoot({
            type: 'mysql',
            host: 'localhost',
            port: 3606,
            // port: 3308,
            username: 'zht',
            password: 'Zborui@090329',
            // password: 'zht780214',
            database: 'baoxu_cfs',
            entities: [],
            synchronize: false,
            // supportBigNumbers: true,
            retryDelay: 500, // 重试链接数据据库间隔时间
            retryAttempts: 3, // 重试链接数据据库次数
            autoLoadEntities: true, // 通过 forFeature() 方法注册的每个实体都将自动添加到配置对象的 entities 数组中。
            logging: true,
            logger: new CustomTypeOrmLogger(),
            // subscribers: [DecimalTransformer],
        }),
        LoginModule,
        UploadModule,
        SysModule,
        AuthModule,
        BasedataModule,
        SharedModule,
        ContainerModule,
        BusinessModule,
        CfsModule,
        TransportModule,
        
    ],
    controllers: [AppController],
    providers: [AppService],
    exports: []
    
})
export class AppModule implements NestModule{
    configure(consumer: MiddlewareConsumer) {
        // throw new Error('Method not implemented.');
        // consumer.apply(LoggerMiddleware).forRoutes(LoginController);
    }
}
